package com.tianyi.sfzy1.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tianyi.sfzy1.domain.Member;
import com.tianyi.sfzy1.domain.Privatemessage;
import com.tianyi.sfzy1.mapper.MemberMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MemberService {
    @Autowired
    private MemberMapper memberMapper;
//    会员登录
    public int login(String username, String password) {
        Member member = memberMapper.login(username,password);
        if (member != null && member.getPassword().equals(password)) {
            //密码正确
            return 1;
        } else {
            //账号或密码错误
            return 0;
        }
    }

//    会员注册
    public int register(Member member) {
        return memberMapper.register(member);
    }

    //根据用户名或电话查询会员信息
    public Member selectByUsername(String username) {
        return memberMapper.selectByUsername(username);
    }

//    根据用户名修改会员手机号
    public int updatePhoneByUsername(String username, String mobile) {
        return memberMapper.updatePhoneByUsername(username,mobile);
    }

//    根据用户名修改会员密码
    public int updateByUsername(String username, String password) {
        return memberMapper.updateByUsername(username,password);
    }
//    查找所有会员信息
    public List<Member> findAll(){
        return memberMapper.findAll();
    }

    // 查询所有会员信息，包含会员积分
    public List<Member> findAllWithPoints() {
        return memberMapper.findAllWithPoints();
    }

    //查询所有会员信息，包含会员积分(分页)
    public PageInfo<Member> findAllWithPointsPage2(int pageNum,int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Member> MemberList = memberMapper.findAllWithPointsPage(pageNum,pageSize);
        PageInfo<Member> pageInfo = new PageInfo<>(MemberList);
        return pageInfo;
    }

    //根据咨询师id查询预约信息
    public List<Member> findAllConsultationappointment(int id){
        return memberMapper.findAllConsultationappointment(id);
    }

    //查询所有预约咨询信息
    public List<Member> findAllConsultation(){
        return memberMapper.findAllConsultation();
    }

    //可以通过咨询师编号或者会员姓名，或者两者同时查询 对应的Consultation
    public List<Member> findConsultation(String name){
        return memberMapper.findConsultation(name);
    }

    public List<Member> findconsultationappointment(int mid){
        return memberMapper.findconsultationappointment(mid);
    }

//    插入会员信息
    public int insertMember(Member member){
        return memberMapper.insertMember(member);
    }

    //根据用户名查询会员信息
    public Member selectByUsername1(String username){
        return memberMapper.selectByUsername1(username);
    }

    //根据用户名修改会员信息
    public int updateByUsername1(Member member){
        return memberMapper.updateByUsername1(member);
    }

    //根据用户名删除会员信息
    public int deleteByUsername(String username){
        return memberMapper.deleteByUsername(username);
    }

    //根据会员姓名查询会员信息(模糊查询)
    public List<Member> selectByUsername2(String realname){
        return memberMapper.selectByUsername2(realname);
    }

    //根据会员编号删除会员信息(批量删除)
    public int deleteByIds(List<Integer> memberId){
        return memberMapper.deleteByIds(memberId);
    }

    //查询所有会员的数量
    public int selectCount(){
        return memberMapper.selectCount();
    }
}
